package dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import modelos.Kits;

public class DAOKits
{
	private Connection connection;
	private PreparedStatement comando;
	private ResultSet result;
	
	public DAOKits()
	{
		connection = ConnectionFactory.createConnection();
	}
	
	public void insereKits(int idMarca, int idModelo, int idversao, String nome, int idAcessorio1, int idAcessorio2, int idAcessorio3, int idAcessorio4, int idAcessorio5, double preco) throws SQLException
	{
		comando = connection.prepareStatement("INSERT INTO kit (id_marca, id_modelo, id_versao, nome, id_acessorios_1, id_acessorios_2, id_acessorios_3, id_acessorios_4, id_acessorios_5, preco ) VALUES (?,?,?,?,?,?,?,?,?)");
		
		comando.setInt(1, idMarca);
		comando.setInt(2, idModelo);
		comando.setInt(3, idversao);
		comando.setString(4, nome);
		comando.setInt(5, idAcessorio1);
		comando.setInt(6, idAcessorio2);
		comando.setInt(7, idAcessorio3);
		comando.setInt(8, idAcessorio4);
		comando.setInt(9, idAcessorio5);
		comando.setDouble(10, preco);
		
		comando.execute();
	}
	
	public List<Kits> buscaKits() throws SQLException
	{
		List<Kits> kits = new ArrayList<Kits>();
		Kits kit = null;
		
		comando = connection.prepareStatement("SELECT * FROM kits");
		
		result = comando.executeQuery();
		
		while(result.next())
		{
			kit = new Kits();
			
			kit.setId(result.getInt("id"));
			kit.setIdMarca(result.getInt("id_marca"));
			kit.setIdModelo(result.getInt("id_modelo"));
			kit.setIdversao(result.getInt("id_versao"));
			kit.setIdAcessorio1(result.getInt("id_acessorios_1"));
			kit.setIdAcessorio2(result.getInt("id_acessorios_2"));
			kit.setIdAcessorio3(result.getInt("id_acessorios_3"));
			kit.setIdAcessorio4(result.getInt("id_acessorios_4"));
			kit.setIdAcessorio5(result.getInt("id_acessorios_5"));
			kit.setNome(result.getString("nome"));
			
			kits.add(kit);
		}
		return kits;
	}
}
